<?php
require_once dirname(__FILE__).'/../bootstrap/doctrine.php';
$t = new lime_test(40);

//测试获取动态信息总数函数
$t->comment('1.Test function getSum');
$t->comment('  1.1.getSum() is belongs to dynamicinfomationTable?');
$t->can_ok('dynamicinfomationTable', 'getSum', 'dynamicinfomationTable has the getSum() function');
$t->comment('  1.2.getSum() returns 12 infomations?');
$t->is(Doctrine_Core::getTable('dynamicinfomation')->getSum(), '12', 'yes!getSum() returns 12 infomations');

//测试获取工作动态的查询函数（包括未激活的并倒序）
$t->comment('2.Test function retrieveBackendNewsList');
$t->comment('  2.1.retrieveBackendNewsList() returns a Doctrine_Query?');
$t->isa_ok(Doctrine_Core::getTable('dynamicinfomation')->retrieveBackendNewsList(), 'Doctrine_Query');
$t->comment('  2.2.fetch one object from results of retrieveBackendNewsList() in witch category id is 3 ?');
$t->is(Doctrine_Core::getTable('dynamicinfomation')->retrieveBackendNewsList()->fetchOne()->getCategoryId(), '3');

//测试获取工作动态的查询函数（只包括激活的并倒序）
$t->comment('3.Test function retrieveNewsListQuery');
$t->comment('  2.1.retrieveNewsListQuery() returns a Doctrine_Query?');
$t->isa_ok(Doctrine_Core::getTable('dynamicinfomation')->retrieveNewsListQuery(), 'Doctrine_Query');
$t->comment('  2.2.fetch one object from results of retrieveNewsListQuery() in witch category id is 2 ?');
$t->is(Doctrine_Core::getTable('dynamicinfomation')->retrieveNewsListQuery()->fetchOne()->getCategoryId(), '2');

//测试获取营养学堂的函数
$t->comment('4.Test function retrieveBackendSchoolsList');
$t->comment('  4.1.retrieveBackendSchoolsList() returns a Doctrine_Collection?');
$t->isa_ok(Doctrine_Core::getTable('dynamicinfomation')->retrieveBackendSchoolsList()->execute(), 'Doctrine_Collection');
$t->comment('  4.2.fetch one object from results of retrieveBackendSchoolsList() in witch category id is 4 ?');
$t->is(Doctrine_Core::getTable('dynamicinfomation')->retrieveBackendSchoolsList()->fetchOne()->getCategoryId(), '4');

//测试获取工作动态列表的函数（仅激活的，倒序）
$t->comment('5.Test function getNewsList');
$t->comment('  5.1.getNewsList() returns a Doctrine_Collection?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->getNewsList(), 'Doctrine_Collection');
$t->is($news[0]->getIsActive(), ture, 'everyOne is actived!');
$t->comment('  5.2.check the result?');
$t->is($news[0]->c_groups, '工作动态', 'the groups is news');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态1');
$t->is($news[0]->getId(), $collection1[0]->getId(), sprintf('the id is %s', $collection1[0]->getId()));
unset($news,$collection1);

//测试获取工作动态列表的函数（包括未激活的，倒序）
$t->comment('6.Test function retriveNewsList');
$t->comment('  6.1.retriveNewsList() returns a Doctrine_Collection?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->retriveNewsList(), 'Doctrine_Collection');
$t->comment('  6.2.check the result?');
$t->is($news[0]->getIsActive(), FALSE, 'everyOne isn\'t actived!');
$t->is($news[0]->c_groups, '工作动态', 'the groups is news');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态_未激活');
$t->is($news[0]->getId(), $collection1[0]->getId(), sprintf('the id is %s', $collection1[0]->getId()));
unset($news,$collection1);

//测试获取工作动态列表，仅激活的，倒序，最近的两条
$t->comment('7.Test function getLastTwoNews');
$t->comment('  7.1.getLastTwoNews() returns a Doctrine_Collection?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->getLastTwoNews(), 'Doctrine_Collection');
$t->comment('  7.2.check the result?');
$t->is($news->count(), '2', 'just 2 result!');
$t->is($news[0]->getTitle(), '工作动态1', 'the first title is 工作动态_1!');
$t->is($news[0]->getIsActive(), true, 'the first status is actived!');
$t->is($news[1]->getTitle(), '工作动态2', 'the second title is 工作动态_2!');
$t->is($news[1]->getIsActive(), true, 'the second status is actived!');
unset($news);



//测试获取最新两条工作动态的对象，并将它们的id赋值给ids数组变量的函数
$t->comment('8.Test function getIdFromLastTwoNews');
$t->comment('  8.1.getIdFromLastTwoNews() returns a Array?');
$t->isa_ok($newsid = Doctrine_Core::getTable('dynamicinfomation')->getIdFromLastTwoNews(), 'array');
$t->comment('  8.2.check the result?');
$t->is(count($newsid), '2', 'just 2 result!');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态1');
$collection2 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态2');
$t->is($newsid[0], $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
$t->is($newsid[1], $collection2[0]->getId(),sprintf('the second id is %s!',$collection2[0]->getId()));
unset($newsid,$collection1,$collection2);

//测试获取工作动态列表，除了最新的两个对象，激活，倒序方法
$t->comment('9.Test function retriveNewsListExceptLastTwo');
$t->comment('  9.1.retriveNewsListExceptLastTwo() returns a Doctrine_Collection?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->retriveNewsListExceptLastTwo(), 'Doctrine_Collection');
$t->comment('  9.2.check the result?');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态3');
$t->is($news[0]->getId(), $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
unset($news,$collection1);



//测试获取工作动态列表的pager对象，除了最新的两个，激活，倒序
$t->comment('10.Test function retriveNewsListExceptLastTwoPager');
$t->comment('  10.1.retriveNewsListExceptLastTwoPager() returns a sfDoctrinePager?');
$t->isa_ok($pager = Doctrine_Core::getTable('dynamicinfomation')->retriveNewsListExceptLastTwoPager(1), 'sfDoctrinePager');
$t->comment('  10.2.check the result?');
$news = $pager->getResults();
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态3');
$t->is($news[0]->getId(), $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
$t->is($pager->getPage(), '1', 'default page is 1');
unset($news,$collection1, $pager);

//测试获取热门工作动态对象方法，激活，按被浏览数倒序
$t->comment('11.Test function getHotNews');
$t->comment('  11.1.getHotNews() returns a Doctrine_Collection?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->getHotNews(2), 'Doctrine_Collection');
$t->comment('  11.2.check the result?');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态5');
$t->is($news[0]->getId(), $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
$t->is($news->count(),'2','has 2 results according to argument');
unset($news,$collection1);

//测试获取置顶的对象，激活，时间倒序，1个
$t->comment('12.Test function getTopnews');
$t->comment('  12.1.getTopnews() returns a dynamicinfomation object?');
$t->isa_ok($news = Doctrine_Core::getTable('dynamicinfomation')->getTopnews(), 'dynamicinfomation');
$t->comment('  12.2.check the result?');
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('工作动态_置顶');
$t->is($news->getId(), $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
unset($news,$collection1);

//测试获取营养列表的函数
$t->comment('13.Test function getSchoolsList');
$t->comment('  13.1.getSchoolsList() returns a Doctrine_Collection?');
$t->isa_ok(Doctrine_Core::getTable('dynamicinfomation')->getSchoolsList(), 'Doctrine_Collection');

//测试获取营养列表的函数
$t->comment('14.Test function getSchoolsListPager');
$t->comment('  14.1.getSchoolsListPager() returns a sfDoctrinePager?');
$t->isa_ok($pager = Doctrine_Core::getTable('dynamicinfomation')->getSchoolsListPager(1), 'sfDoctrinePager');
$t->comment('  14.2.check the result?');
$schools = $pager->getResults();
$collection1 = Doctrine_Core::getTable('dynamicinfomation')->findByTitle('营养学堂知识6');
$t->is($schools[0]->getId(), $collection1[0]->getId(), sprintf('the first id is %s!',$collection1[0]->getId()));
$t->is($pager->getPage(), '1', 'default page is 1');
unset($schools,$collection1, $pager);
?>
